<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link href="./css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <div class="container" style="padding-top: 20px;">
    <div class="panel panel-primary">
      <div class="panel-heading">基础用法</div>
      <div class="panel-body">
        <div class="form-group">
          <label for="url">下载地址</label>
          <input class="form-control" id="url" type="text" value="https://down.sandai.net/ThunderVIP/ThunderVIP-xlgw.exe" placeholder="请输入下载地址。">
        </div>
        <div class="form-group">
          <a  class="thunder-link btn btn-primary btn-block" href="https://down.sandai.net/ThunderVIP/ThunderVIP-xlgw.exe">点击下载</a>
        </div>

      </div>

    </div>

    <div class="panel panel-primary">
      <div class="panel-heading">单文件下载</div>
      <div class="panel-body">
        <div class="form-group">
          <label for="download-dir">下载目录</label>
          <input class="form-control" id="download-dir" type="text" value="我的应用" placeholder="请输入下载目录。">
        </div>
        <div class="form-group">
          <label for="name">文件名称</label>
          <input class="form-control" id="name" type="text" value="ThunderVIP-xlgw.exe" placeholder="请输入任务名称。">
        </div>
        <div class="form-group">
          <label for="url">设置referer</label>
          <input class="form-control" id="referer" type="text" value="" placeholder="请输入referer。">
        </div>
        <div class="form-group">
          <label for="url">下载地址</label>
          <input class="form-control" id="url" type="text" value="https://down.sandai.net/ThunderVIP/ThunderVIP-xlgw.exe" placeholder="请输入下载地址。">
        </div>
        <button class="btn btn-primary btn-block" id="single-task" type="submit">迅雷下载</button>
      </div>
    </div>



    <div class="panel panel-primary">
      <div class="panel-heading">高级用法</div>
      <div class="panel-body">
          <div class="form-group">
              <label for="download-minVersion">迅雷最低版本号</label>
              <input class="form-control" id="download-minVersion" type="text" value="10.0.1.0" placeholder="请输入迅雷最低版本号">
          </div>
          <div class="form-group">
            <label for="download-install-pack">迅雷专属下载链接</label>
            <input class="form-control" id="download-install-pack" type="text" value="" placeholder="请输入迅雷专属下载链接">
        </div>
        <div class="form-group">
          <label for="download-dir2">下载目录</label>
          <input class="form-control" id="download-dir2" type="text" value="我的应用" placeholder="请输入下载目录。">
        </div>
        <div class="form-group">
          <label for="install-file">安装文件</label>
          <input class="form-control" id="install-file" type="text" placeholder="请输入安装文件。">
        </div>
        <div class="form-group">
          <label for="create-short-cut">快捷方式</label>
          <input class="form-control" id="create-short-cut" type="text" placeholder='请输入快捷方式, 示例: { "name": "测试", "targetFile":"thunder9/OnlineInstall9.1.49.1060xl.exe", "runParams": "--StartType:DeskTop", "startIn": "D:/Program Files" }'>
        </div>
        <div class="form-group">
          <label for="hide-yun-pan">隐藏云盘入口</label>
          <input class="form-control" id="hide-yun-pan" type="text" value="'1'" placeholder="请输入是否隐藏云盘入口, '1' 或 '0'">
        </div>
        <div class="form-group">
          <label for="task-group-name">任务组名称</label>
          <input class="form-control" id="task-group-name" value="迅雷产品大全" type="text" placeholder="请输入任务组名称。">
        </div>
        <div class="form-group">
          <label for="task-group-thread">下载线程数量</label>
          <input class="form-control" id="task-group-thread" value=10 type="text" placeholder="请输入下载线程数量">
        </div>
        <div class="form-group">
          <label for="task-group-userAgent">UserAgent</label>
          <input class="form-control" id="task-group-userAgent" value="My-User-Agent" type="text" placeholder="请输入UserAgent">
        </div>
        <div class="form-group">
          <label for="task-group-name">URL排除路径</label>
          <input class="form-control" id="task-group-exclude-prefix" value="https://down.sandai.net" type="text" placeholder="请输入排除路径的URL前缀。">
        </div>
        <div class="form-group">
          <label for="url">设置referer</label>
          <input class="form-control" id="task-referer" type="text" value="" placeholder="请输入referer。">
        </div>
        <div class="form-group">
          <label for="tasks">下载地址</label>
          <textarea class="form-control" id="tasks" rows="5" placeholder="请输入下载地址，请确保每行只有一个链接。">
https://down.sandai.net/thunder9/OnlineInstall9.1.49.1060xl.exe
https://down.sandai.net/ThunderVIP/ThunderVIP-xlgw.exe
https://down.sandai.net/mac/thunder_3.2.2.3574.dmg
https://down.sandai.net/XLNetAcc/XLNetAccSetup.exe
http://xmp.down.sandai.net/xmp/XMPSetup_5.4.0.6151-dl.exe
https://down.sandai.net/XLFileMail/XLFileMailSetup.exe
https://down.sandai.net/xljiasu/XlaccSetup3.17.0.9122_jsqgw.exe
          </textarea>
        </div>
        <button class="btn btn-primary btn-block" id="multi-task" type="submit">迅雷批量下载</button>
      </div>
    </div>


    <div class="panel panel-primary">
      <div class="panel-heading">边下边播</div>
      <div class="panel-body">
        <div class="form-group">
          <label for="name">文件名称</label>
          <input class="form-control" id="sp-name" type="text" value="" placeholder="请输入任务名称。">
        </div>
        <div class="form-group">
          <label for="url">设置referer</label>
          <input class="form-control" id="sp-referer" type="text" value="" placeholder="请输入referer。">
        </div>
        <div class="form-group">
          <label for="url">下载地址</label>
          <input class="form-control" id="sp-url" type="text" value="magnet:?xt=urn:btih:08ADA5A7A6183AAE1E09D831DF6748D566095A10" placeholder="请输入下载地址。">
        </div>
        <button class="btn btn-primary btn-block" id="down-and-play" type="submit">边下边播</button>
      </div>
    </div>
    <div class="panel panel-primary">
      <div class="panel-heading">通过后台配置文件下载</div>
      <div class="panel-body">
          <div class="form-group">
              <label for="download-minVersion">迅雷最低版本号</label>
              <input class="form-control" id="config-download-minVersion" type="text" value="10.1.2.0" placeholder="请输入迅雷最低版本号">
          </div>
          <div class="form-group">
            <label for="download-install-pack">迅雷专属下载链接</label>
            <input class="form-control" id="config-download-install-pack" type="text" value="https://down.sandai.net/thunderx/XunLeiSetup10.1.1.148Beta.exe" placeholder="请输入迅雷专属下载链接">
        </div>

        <div class="form-group">
          <label for="task-group-name">任务组名称</label>
          <input class="form-control" id="config-task-group-name" value="迅雷产品大全" type="text" placeholder="请输入任务组名称。">
        </div>
        <div class="form-group">
          <label for="url">设置referer</label>
          <input class="form-control" id="config-referer" type="text" value="" placeholder="请输入referer。">
        </div>
        <div class="form-group">
          <label for="url">后台配置地址</label>
          <input class="form-control" id="config-json-url" type="text" value="http://open.thunderurl.com/test/download.json" placeholder="请输入后台配置下载资源">
        </div>
        <button class="btn btn-primary btn-block" id="config-json-task" type="submit">从后台配置下载资源</button>
      </div>
    </div>

  </div>
  <script src="./js/jquery.min.js"></script>
  <script src="./js/thunder-link.js"></script>
  <script>
    thunderLink();

    $('#url').bind('input', function (e) {
      $('.thunder-link').attr('href', e.target.value)
      thunderLink();
    })

    $('#single-task').click(function () {
      var downloadDir = $('#download-dir').val();
      var name = $('#name').val();
      var url = $('#url').val();
      var referer = $('#referer').val();

      thunderLink.newTask({
        downloadDir: '',
        tasks: [{
          name: name,
          url: url
        }],
        referer: ''
      });
    });

    $('#config-json-task').click(function () {
      var taskGroupName = $('#config-task-group-name').val();
      var minVersion =  $('#config-download-minVersion').val();
      var installPack = $('#config-download-install-pack').val();
      var json = $('#config-json-url').val();
      var referer = $('#config-referer').val();

      thunderLink.newTask({
        minVersion: minVersion , // 指定响应批量任务的迅雷最低版；格式匹配：/^\d+\.\d+\.\d+(?:\.\d+)?$/,
        thunderInstallPack: installPack,
        taskGroupName: taskGroupName,
        json: json,
        referer: referer
      });
    });
    $('#multi-task').click(function () {
      var downloadDir = $('#download-dir2').val();
      var installFile = $('#install-file').val();
      var taskGroupName = $('#task-group-name').val();
      var prefix = $('#task-group-exclude-prefix').val();
      var minVersion =  $('#download-minVersion').val();
      var installPack = $('#download-install-pack').val();
      var links = $('#tasks').val().split('\n');
      var threadCount = parseInt($('#task-group-thread').val(), 10);
      var userAgent = $('#task-group-userAgent').val();
      var createShortcut = $('#create-short-cut').val();
      var hideYunPan = $('#hide-yun-pan').val() || '0';
      try {
        createShortcut = JSON.parse(createShortcut);
      } catch (e) {
        createShortcut = {
          name: '测试',
          targetFile: 'thunder9/OnlineInstall9.1.49.1060xl.exe',
          runParams: 'a'
        }
      }
      var tasks = [];
      for (idx in links) {
        var task = {url: links[idx], dir: ""};
        tasks.push(task);
      }
     var opts =   {
        downloadDir: downloadDir,
        installFile: installFile,
        taskGroupName: taskGroupName,
        tasks: tasks,
        excludePath: prefix,
        minVersion: minVersion,
        createShortcut,
        hideYunPan,
      };
      if (installPack !== undefined && /^\s*https?:\/\/(.+?\.)?down\.sandai\.net/gi.test(installPack)) {
        opts.thunderInstallPack = installPack;
      }

      if (userAgent !== '') {
        opts.userAgent = userAgent;
      }

      if (threadCount > 0) {
        opts.threadCount = threadCount;
      }

      opts.referer = $('#task-referer').val();

      thunderLink.newTask(opts);
    });
    $('#down-and-play').click(function () {
      thunderLink.downAndPlayWithXmp({
        tasks: [{
          name: $('#sp-name').val(),
          url: $('#sp-url').val(),
          referer: $('#sp-referer').val()
        }]
      })
    })
  </script>
</body>
</html>
